from page.net_project_page import NetProjectPage
from page.common_tools import CommonTools
from common.page import IOS, XPATH
import random as r
import time as t


today = t.strftime('%Y%m%d', t.localtime(t.time()))


class zizhuCommPage(NetProjectPage, CommonTools):
    # 交流详情页面
    comment_text = (XPATH, '//XCUIElementTypeStaticText[@name="请输入内容"]/../XCUIElementTypeTextView')

    def release_comm(self, title='%s自动化测试交流%d' % (today, r.randint(100, 999))):
        self.find_button("common release").click()
        self.find_element(XPATH,"//XCUIElementTypeTextField[contains(@value,'请输入标题')]").send_keys(title)
        self.find_element(XPATH, "//XCUIElementTypeTextView[contains(@value,'请输入内容')]").send_keys('这是交流的内容。他敢于践踏任何美好的东西，包括爱情、友谊、荣誉，而且内心没有丝毫不安。这样的人尽管有再多的艳遇，也没有能力真正爱一回；结交再多的哥们，也体味不了友谊的纯正；获取再多的名声，也不知什么是光荣。不相信神圣 的人，必被世上一切神圣的事物所抛弃。。。。。')

        self.hide_keyboard()
        # self.get_frame_center_and_click(self.find_static_text("添加图片"), flag=0)
        self.find_element(XPATH,'//*[@name="common_camera_icon"]').click()
        self.tacke_photo()
        self.find_button("下一步").click()
        self.find_button("commontool review unselected").click()
        self.find_button("我同意").click()
        self.find_button("发布").click()
        t.sleep(3)

    def enter_comm(self, title):
        self.find_element(IOS, 'type == "XCUIElementTypeStaticText" AND label CONTAINS "%s"' % title).click()

    def view_comment_comm(self, title='自动化测试交流%d' % (r.random())):
        self.CaoG()

        self.find_static_text(string="全部交流", contains_flag=1).click()
        t.sleep(3)
        self.find_static_text(string="我的草稿", contains_flag=1).click()
        self.find_static_text("编辑").click()
        self.find_button("下一步").click()
        self.find_static_text(string="公开方式", contains_flag=1).click()
        self.find_button("确定").click()
        self.find_button("commontool review unselected").click()
        self.find_button("我同意").click()
        self.find_button("更新草稿").click()
        t.sleep(1)
        self.find_static_text("删除").click()
        self.find_button("确定").click()
        self.find_button("common back dark icon").click()
        t.sleep(0.5)
        self.find_button("common back light icon").click()

if __name__ == '__main__':
    test = zizhuCommPage()
    test.enter_project()
    test.enter_tools('交流')
    test.release_comm()
    test.view_comment_comm()
